<template>
  <!--实体ID策略-->
  <section class="page outsource-commission">
    <data-form :model="model" @onSearch="refreshData" autoSearch :page="pageService">
      <template slot="inputs">
        <el-form-item label="实体注记" prop="strategyName">
          <el-input v-model.trim="model.strategyName" clearable></el-input>
        </el-form-item>
        <el-form-item label="策略状态" prop="commonState">
          <el-select v-model="model.commonState" placeholder="请选择" clearable>
            <el-option v-for="{ index, name, code } in $dict.getDictData( 'CommonState' )" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
      </template>
    </data-form>
    <data-box @onPageChange="refreshData" :data="dataSet" :page="pageService">
      <template slot="buttons">
        <el-button @click="addClick" v-auth="23290">新增策略</el-button>
      </template>
      <template slot="columns">
        <el-table-column label="操作" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <el-button @click="modifyClick(scope)" :disabled="scope.row.applyStatus==='PENDING'?true:false" type="text" v-auth="23291">编辑</el-button>
            <el-button @click="seeModify(scope)" type="text">查看</el-button>
            <!-- <el-button @click="onClickDelete(scope.row)" type="text">删除</el-button> -->
          </template>
        </el-table-column>
        <el-table-column prop="priorityNo" label="优先级" :min-width="$helper.getColumnWidth(2)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="strategyName" label="实体注记" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="commonState" label="策略状态" :min-width="$helper.getColumnWidth(3)" :formatter="(row) => $filter.dictConvert(row.commonState,'CommonState')" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="entityTypeCode" label="实体类型码" :min-width="$helper.getColumnWidth(2)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="modifyOperatorRealName" label="修改人" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="timeModified" label="修改时间" :formatter="row => $filter.dateTimeFormat(row.timeModified)" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="approvalRealName" label="复核人" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="approvalTime" label="复核时间" :formatter="row => $filter.dateTimeFormat(row.approvalTime)" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="strategyNotes" label="注记" show-overflow-tooltip :min-width="$helper.getColumnWidth(5)">
        </el-table-column>
        <el-table-column label="审批记录" :min-width="$helper.getColumnWidth(4)">
          <template slot-scope="scope">
            <el-button @click="log(scope),modifyData.type='EntityId'" type="text">查看</el-button>
          </template>
        </el-table-column>
      </template>
    </data-box>

    <!--新增/修改实体策略-->
    <el-dialog :title="operationType.DEFAULT==='OPERATION_ADD'?'新增实体策略':operationType.DEFAULT==='OPERATION_SEE'?'查看':' 修改实体策略'" @close="dialog.config = false" :visible.sync="dialog.config" :close-on-click-modal="false" :show-close="true" width="820px" @open="$nextTick(()=>$refs['add-strategic'].refresh(modifyData))">
      <add-strategic ref="add-strategic" :modifyData="modifyData" @close="dialog.config = false" :show="show" @refreshData="refreshData"></add-strategic>
    </el-dialog>

    <el-dialog title="实体策略日志" @close="dialog.seeLog = false" :visible.sync="dialog.seeLog" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="true" width="800px" @open="$nextTick(() => $refs['see-log'].refreshData())">
      <see-log ref="see-log" :modifyData="modifyData" @refreshData="refreshData"></see-log>
    </el-dialog>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Layout, Dependencies, Auth } from "~/core/decorator";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import AddStrategic from "~/components/strategic-manage/add-strategic.vue";
import { EntityIdService } from "~/services/management-service/entity-id.service";
import { PageService } from "~/utils/page.service";
import SeeLog from "~/components/strategic-manage/see-log.vue";
import { OPERATION_TYPE } from "~/config/enum.config";

@Auth(2329)
@Layout("workspace")
@Component({
  components: {
    AddStrategic,
    SeeLog
  }
})
export default class EntityId extends Vue {
  @Dependencies(EntityIdService)
  private entityIdService: EntityIdService;
  @Dependencies(PageService)
  private pageService: PageService;
  // 页面按钮类型
  private operationType: any = OPERATION_TYPE
  // 数据列表
  private dataSet: any[] = [];
  // 当前行数据
  private rowData: any = null;
  // 弹框控制
  private dialog: any = {
    config: false,
    seeLog: false
  };
  private show: any = false;
  private modifyData: any = {};
  private model: any = {
    strategyName: "",
    commonState: "",
    id: ""
  };

  /**
   * 获取策略列表
   */
  private refreshData () {
    this.entityIdService
      .getEntityId(this.model, this.pageService)
      .subscribe(data => {
        data.map(f => {
          f.entityTypeCode = f.entityType + f.entityCode
        })
        this.dataSet = data;
      });
  }

  /**
   * 新增点击
   */
  private addClick () {
    this.modifyData = {};
    this.operationType.DEFAULT = 'OPERATION_ADD';
    this.show = false;
    this.dialog.config = true;
  }

  /**
   * 修改点击
   */
  private modifyClick (scope) {
    this.operationType.DEFAULT = 'OPERATION_EDIT';
    this.modifyData = { ...scope.row };
    this.modifyData.type = 'EntityId'
    this.show = false;
    this.dialog.config = true;
  }
  /**
   * 查看
   */
  private seeModify (scope) {
    this.operationType.DEFAULT = 'OPERATION_SEE'
    this.modifyData = { ...scope.row };
    this.modifyData.type = 'EntityId'
    this.show = true;
    this.dialog.config = true;
  }
  /**
   * 删除
   */
  // private onClickDelete (row) {
  //   this.model.id = row.id
  //   this.$confirm("您确定执行该操作吗？", {
  //     confirmButtonText: "确定",
  //     cancelButtonText: "取消"
  //   }).then(() => {
  //     this.entityIdService
  //       .deleteEntityId(this.model)
  //       .subscribe(data => {
  //         this.$message.success("删除成功！");
  //         this.refreshData()
  //       });
  //   });
  // }
  /**
   * 日志
   */
  private log (scope) {
    this.modifyData = scope.row;
    this.dialog.seeLog = true;
  }
  private mounted () {
    this.refreshData();
  }
}
</script>

<style lang="less"></style>
